package project.controllers.workers;

import java.util.ArrayList;
import java.util.GregorianCalendar;

import project.model.IGarage;
import project.model.IMaster;

public class WorkerWithGarage {

	private static final String ALL_GARAGES_BUSY = "All garages busy";
	private static final String EMPTY_GARAGE="Empty garage #"; 
	private static final String PLACE_ON_THIS_DATE = " empty places on this date";
	

	static void getEmptyGarage(ArrayList<IGarage> garageList) {
		boolean temp = false;
		for (IGarage garage : garageList) {
			if (garage.getEmptyGarage()) {
				System.out.println(EMPTY_GARAGE + garage.getNumberGarage());
				temp = true;
			}
		}

		if (temp == false) {
			System.out.println(ALL_GARAGES_BUSY);
		}
	}

	static void getNumberEmptyPlaces(ArrayList<IMaster> masterList,
			ArrayList<IGarage> garageList,GregorianCalendar date) {
		ArrayList<IGarage> garageEmpty = new ArrayList<IGarage>();
		ArrayList<IMaster> masterFree = new ArrayList<IMaster>();

		for (IGarage garage : garageList) {
			if (garage.getOrder().getDeadlineDate().before(date)
					|| garage.getEmptyGarage()) {
				garageEmpty.add(garage);
			}
		}

		for (IMaster master : masterList) {
			if (master.getOrder().getDeadlineDate().before(date)
					|| master.getEmploymentMaster() == false) {
				masterFree.add(master);
			}
		}

		if (masterFree.size() > garageEmpty.size()) {
			System.out.println(garageEmpty.size()
					+ PLACE_ON_THIS_DATE);
		} else if (masterFree.size() < garageEmpty.size()) {
			System.out.println( masterFree.size()
					+ PLACE_ON_THIS_DATE);
		} else if (masterFree.size() == garageEmpty.size()) {
			System.out.println(garageEmpty.size()
					+ PLACE_ON_THIS_DATE);
		}

	}
	
	static void addGarage(ArrayList<IGarage> garageList,IGarage garage) {
		garageList.add(garage);
	}

	static void deleteGarage(ArrayList<IGarage> garageList,IGarage garage) {
		ArrayList<IGarage> temp = new ArrayList<IGarage>();
		for (IGarage gar :garageList) {
			if (!gar.equals(garage)) {
				temp.add(gar);
			}
		}
		garageList.clear();
		garageList.addAll(temp);
	}
}
